package com.pda.xinmazhi.presenter;

import com.pda.xinmazhi.bean.LoginBean;
import com.pda.xinmazhi.bean.OtherInfoBean;
import com.pda.xinmazhi.bean.ScanResultBean;
import com.pda.xinmazhi.bean.request.OtherRequest;
import com.pda.xinmazhi.bean.request.QRcodeRequest;
import com.pda.xinmazhi.contract.OtherOutContract;
import com.pda.xinmazhi.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class OtherOutPresenter extends BasePresenter<OtherOutContract.View> implements OtherOutContract.Presenter {

    @Override
    public void getOtherInfo(String storageBinId, String container) {
        NetUtils.geApi().getOtherInfo(storageBinId, container)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<OtherInfoBean>>() {
                    @Override
                    public void accept(BaseAppEntity<OtherInfoBean> otherInfoBeanBaseAppEntity) throws Exception {
                        getView().setData(otherInfoBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void scanTheQRCodeToVerify(String code) {
        QRcodeRequest request = new QRcodeRequest();
        request.setQRCode(code);
        NetUtils.geApi().scanTheQRCodeToVerify(request)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<ScanResultBean>>() {
                    @Override
                    public void accept(BaseAppEntity<ScanResultBean> scanResultBeanBaseAppEntity) throws Exception {
                        getView().setScanBean(scanResultBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void otherConfrim(OtherRequest body) {
        NetUtils.geApi().otherConfrim(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<LoginBean>>() {
                    @Override
                    public void accept(BaseAppEntity<LoginBean> loginBeanBaseAppEntity) throws Exception {
                        getView().showMessage(loginBeanBaseAppEntity.getMessage());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
